package com.hdd.config;

import com.hdd.biz.finance.dto.WithdrawVerifyRequest;
import com.hdd.biz.finance.service.WithdrawService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RedisExpiredListener implements MessageListener {

    @Autowired
    private WithdrawService service;
    WithdrawVerifyRequest request;
    @Override
    public void onMessage(Message message, byte[] bytes) {
        byte[] body = message.getBody();// 建议使用: valueSerializer
        byte[] channel = message.getChannel();
        System.out.print("onMessage >>+++++++++++++++++++++++++ ");
        System.out.println(String.format("channel: %s, body: %s, bytes: %s"
                , new String(channel), new String(body), new String(bytes)));
        //修改订单,修改商品状态
        String str = String.format("body: %s", new String(body));
        log.info("str:"+str);
        if (str.startsWith("body: withdraw")) {
            String id = str.replace("body: withdraw:","");
            log.info("withdraw:"+id);
            request = new WithdrawVerifyRequest();
            request.setId(Integer.parseInt(id));
            service.verifyWithdraw(request);
        }
    }


}